class VegasController < ApplicationController
  caches_page :index
  def index
    
  end

  def ops
    if [6, 9].include?(params[:id].to_i)
      params[:id] = 2
    end
  end
  
  def xml
    params[:width], params[:height] = case params[:fenbianlv].to_i
      when 1 then [512, 384]
      when 2 then [704, 396]
      when 3 then [640, 384]
    end
    render :xml => eval("xml_#{params[:id]}")
  end

  #part2,6,9: normal list
  def xml_2
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width],
                             :ops => {}}) do |vvm|
     vvm.list1 YAML.load(params[:ops][:yml])
    end
  end

  #part4: pickup
  def xml_4
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width],
                             :ops => YAML.load(params[:ops][:yml]).merge(params[:ops])}) do |vvm|
      vvm.pickup 1..params[:ops]['pickup_count'].to_i
    end
  end

  #part7: 榜外推荐
  def xml_7
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width],
                             :ops => {}}) do |vvm|
      vvm.play_bgm('a-3s-new.wav') do
        vvm.pics "rest", [1], :length => 4
      end
     vvm.list1 YAML.load(params[:ops][:yml])
    end
  end

  #part10: 历史
  def xml_10
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width],
                             :ops => {}}) do |vvm|
      vvm.play_bgm('1.mp3') do
        vvm.pics('weekly', [1], :length => params[:ops][:weekly_length] || 6)
        vvm.history_pic "history", :length => 6
      end
     vvm.list1 YAML.load(params[:ops][:yml])
    end
  end

  #part11: 前三
  def xml_11
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width],
                             :ops => {}}) do |vvm|
     vvm.vvmtime.add_s 1
     vvm.list3(YAML.load params[:ops][:yml]).logo
    end
  end
  
  #part13: ed list
  def xml_13
    BiliRankingMaker.create({:path => params[:ops][:propath],
                             :height => params[:height], :width => params[:width], :ops => {:ed_bgm => params[:ops]}}) do |vvm|
      vvm.ed_bgm do |length|
        if params[:ops][:staff_num].to_i > 1
          vvm.ut[:pic_list] = VegasVideoTime.nl length - 29 if length > 29 #这句计算出每张排名图片停留的时间
          vvm.staffs.title(5, false, 5).list2.ed
        else
          vvm.ut[:pic_list] = VegasVideoTime.nl length - 27 if length > 27 #这句计算出每张排名图片停留的时间
          vvm.staff.title(5, false, 5).list2.ed
        end
      end
    end
  end
end
